import { createOpenAI } from '@ai-sdk/openai';
import { streamText } from 'ai';
// https://neoosyveiiby.bja.sealos.run/#/settings

// Allow streaming responses up to 30 seconds
export const maxDuration = 30;

const openai = createOpenAI({
	apiKey: process.env.OPENAI_API_KEY || '',
	baseURL: 'https://zmgpt.cc/v1',
	compatibility: 'compatible'
});

export async function POST(req: Request) {
	const { messages } = await req.json();
	console.log(req.headers.get('x-forwarded-for') || req.headers.get('remote-addr'), 'ip');

	const result = await streamText({
		model: openai('gpt-3.5-turbo'),
		messages
	});

	return result.toDataStreamResponse();
}
